<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>聊天界面</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 0;
      background-color: #f5f5f5;
    }
    .chat-container {
      display: flex;
      flex-direction: column;
      height: 100vh;
      max-width: 600px;
      margin: 0 auto;
      border: 1px solid #ddd;
      background-color: #fff;
    }
    .chat-header {
      padding: 10px;
      background-color: #08c;
      color: #fff;
      text-align: center;
      font-size: 18px;
    }
    .chat-messages {
      flex: 1;
      overflow-y: auto;
      padding: 10px;
    }
    .message {
      margin-bottom: 10px;
      max-width: 70%;
    }
    .message.sent {
      align-self: flex-end;
      background-color: #fff; /* 用户消息：白色背景 */
      border-radius: 10px 10px 0 10px;
      border: 1px solid #ddd;
    }
    .message.received {
      align-self: flex-start;
      background-color: #e6f7ff; /* AI 消息：浅蓝色背景 */
      border-radius: 10px 10px 10px 0;
      border: 1px solid #b3e5fc;
    }
    .message p {
      margin: 0;
      padding: 10px;
      font-size: 14px;
      word-break: break-word;
    }
    .chat-input {
      display: flex;
      border-top: 1px solid #ddd;
      padding: 10px;
      background-color: #f9f9f9;
    }
    .chat-input textarea {
      flex: 1;
      resize: none;
      border: 1px solid #ddd;
      border-radius: 5px;
      padding: 10px;
      font-size: 14px;
      background-color: #fff;
    }
    .chat-input button {
      margin-left: 10px;
      background-color: #08c;
      color: #fff;
      border: none;
      padding: 10px 20px;
      border-radius: 5px;
      cursor: pointer;
      font-size: 14px;
    }
    .chat-input button:hover {
      background-color: #005f8a;
    }
  </style>
</head>
<body>
<div class="chat-container">
  <div class="chat-header">聊天界面</div>
  <div class="chat-messages" id="chatMessages">
    <div class="message received">
      <p>你好！</p>
    </div>
    <div class="message sent">
      <p>你好！有什么可以帮你的吗？</p>
    </div>
  </div>
  <div class="chat-input">
    <textarea id="messageInput" rows="1" placeholder="输入消息..."></textarea>
    <button onclick="sendMessage()">发送</button>
  </div>
</div>
<script>
  function sendMessage() {
    const input = document.getElementById('messageInput');
    const message = input.value.trim();
    if (message) {
      // 用户消息
      const userMessage = document.createElement('div');
      userMessage.className = 'message sent';
      const userContent = document.createElement('p');
      userContent.textContent = message;
      userMessage.appendChild(userContent);

      document.getElementById('chatMessages').appendChild(userMessage);
      input.value = '';
      input.focus();

      // 滚动到底部
      const chatMessages = document.getElementById('chatMessages');
      chatMessages.scrollTop = chatMessages.scrollHeight;

      // 模拟 AI 回复
      setTimeout(() => {
        const aiMessage = document.createElement('div');
        aiMessage.className = 'message received';
        const aiContent = document.createElement('p');
        aiContent.textContent = `AI：您刚才说的是"${message}"，有需要帮助的地方吗？`;
        aiMessage.appendChild(aiContent);

        document.getElementById('chatMessages').appendChild(aiMessage);
        chatMessages.scrollTop = chatMessages.scrollHeight;
      }, 1000); // 模拟 AI 回复的延迟
    }
  }

  document.getElementById('messageInput').addEventListener('keydown', function (event) {
    if (event.key === 'Enter' && !event.shiftKey) {
      event.preventDefault();
      sendMessage();
    }
  });
</script>
</body>
</html>
